<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath(); %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>成绩管理</title>
<link rel="stylesheet" href="<%=path %>/js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" href="<%=path %>/css/site_main.css"/>
<link rel="stylesheet" type="text/css" href="<%=path %>/js/jquery-easyui/themes/icon.css">
<script type="text/javascript" src="<%=path %>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path %>/js/site_easyui.js"></script>
</head>
<body>
	<table id="list" class="easyui-datagrid" toolbar="#tb" data-options="
		url:'<%=path %>/student/queryAll', 
		method:'get',
		rownumbers: true,
		singleSelect: true,
		autoRowHeight: true,
		pagination:true,
		border:false,
		pageSize:20">
		<thead>
			<tr>
				<th data-options="field:'scoid',checkbox:true,width:100">编号</th>
				<th data-options="field:'stuid',width:100">学生编号</th>
				<th data-options="field:'students',width:100" formatter="studentname">姓名</th>
				<th data-options="field:'sconame',width:100">课程</th>
				<th data-options="field:'score',width:100">分数</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="padding: 2px;">
		<a href="javascript:(0);" class="easyui-linkbutton" onclick="$('#AddWin').dialog('open')" data-options="iconCls:'icon-add'" >添加</a>
		<a href="<%=path %>/student/batch" class="easyui-linkbutton" onclick="" data-options="iconCls:'icon-add'" >批量添加</a>
		<a href="javascript:(0);" class="easyui-linkbutton" onclick="editWin();" data-options="iconCls:'icon-edit'" >编辑</a>
		<a href="javascript:(0);" class="easyui-linkbutton" onclick="expurgate();" data-options="iconCls:'icon-remove'" >删除</a>
	</div>
	
	
	<!-- ----------------------------- 添加  ------------------------------------ -->
	
	<div id="AddWin" class="easyui-window" data-options="closed:true,iconCls:'icon-add'" title="添加学生成绩">
		<table id="addlist" class="easyui-datagrid" toolbar="#addss" data-options="
			url:'<%=path %>/stu/queryAll', 
			method:'get', 
			rownumbers:true,
			singleSelect:true,
			autoRowHeight: true,
			pagination:true,
			border:false,
			pageSize:10"
			style="width:275px;height:240px;padding:10px"
			>
			<thead>
				<tr>
					<th data-options="field:'intenid',checkbox:true,width:100">编号</th>
					<th data-options="field:'intenname',width:100">姓名</th>
					<th data-options="field:'intensex',width:100">性别</th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="addss" style="padding: 2px;">
		<a href="javascript:(0);" class="easyui-linkbutton" onclick="addWin();" data-options="iconCls:'icon-add'" >确认选择</a>
	</div>
	
	<div style="margin:20px 0;"></div>
	<div id="addWindow" class="easyui-window" title="保存" data-options="closed:true,iconCls:'icon-save'" style="padding:10px;">
		<div style="padding:10px 60px 20px 60px">
			<form id="addfrom">
				<table>
					<tr>
						<td><span style="width:100%;height:32px">编号</span></td>
						<td>
							<input name="intenid" id="stuid" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
					<tr>
						<td><span style="width:100%;height:32px">姓名</span></td>
						<td>
							<input name="intenname" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
					<tr>
						<td><span style="width:100%;height:32px">科目</span></td>
						<td>
							<input name="sconame" id="sconame" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
					<tr>
						<td><span style="width:100%;height:32px">分数</span></td>
						<td>
							<input name="score" id="score" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
				</table>
				<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="add();" style="width:80px">保存</a>
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#addWindow').dialog('close')" style="width:80px">取消</a>
				</div>
			</form>
		</div>
	</div>
	
	<div style="margin:20px 0;"></div>
	<div id="editWindow" class="easyui-window" title="编辑" data-options="closed:true,iconCls:'icon-edit'" style="padding:10px;">
		<div style="padding:10px 60px 20px 60px">
			<form id="editfrom">
				<table>
					<tr>
						<td><span style="width:100%;height:32px">编号</span></td>
						<td>
							<input name="stuid" id="estuid" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
					<tr>
						<td><span style="width:100%;height:32px">科目</span></td>
						<td>
							<input name="sconame" id="en" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
					<tr>
						<td><span style="width:100%;height:32px">分数</span></td>
						<td>
							<input name="score" id="ec" class="easyui-textbox" style="width:100%;height:32px">
						</td>
					</tr>
				</table>
				<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Edit();" style="width:80px">保存</a>
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#editWindow').dialog('close')" style="width:80px">取消</a>
				</div>
			</form>
		</div>
	</div>
	
	<!-- ---------------------------------------- 批量  ------------------------------------------- -->
	<div id="adds" class="easyui-window" title="请输入科目名称" data-options="closed:true,iconCls:'icon-edit'" >
		<div style="padding:20px 10px 20px 10px">
		<form id="addsform">
			<table>
				<tr>
					<td><span style="width:100%;height:32px">科目名称</span></td>
					<td>
						<input id="subject" class="easyui-textbox" style="width:100%;height:32px">
					</td>
				</tr>
			</table>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="subject();" style="width:80px">确定</a>
					<a href="javascript:(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#adds').dialog('close')" style="width:80px">取消</a>
				</div>
		</form>
		</div>
	</div>
	
	
	<script type="text/javascript">
		$(function() {
			setPagination("list");
		});
		
		function setPagination(tableId) {
			var p = $("#" + tableId).datagrid("getPager");
			$(p).pagination({
				pageList:[5,10, 15,20],
				beforePageText:"第",
				afterPageText:"页    共{pages}页",
				displayMsg:"当前显示{from} - {to} 条记录    共{total}条记录",
				onBeforeRefresh:function() {
					$(this).pagination("loading");
					$(this).pagination("loaded");
				}
			});
		}
		
		function subject() {
			var subject = $("#subject").val();
			$.post('student/batch',{'subject':subject},"JSON");
			$('#adds').dialog('close');
		}

		function addWin() {
			var row = $("#addlist").datagrid('getSelected');
			if (row){
				$("#addfrom").form("load", row);
				$('#AddWin').dialog('close');
				$('#addWindow').dialog('open');
			}
		}
		
		function add() {
			var stuid = $("#stuid").val();
			var score = $("#score").val();
			var sconame = $("#sconame").val();
			$.get('student/add',{'grade.stuid':stuid,'grade.score':score,'grade.sconame':sconame},"JSON");
			$("#list").datagrid('reload');
			$('#addWindow').dialog('close');
			$("#addfrom").form("clear");
			$("#list").datagrid('reload');
		}
		
		function editWin() {
			var row = $("#list").datagrid("getSelected");
			if (row) {
				$("#editfrom").form("load", row);
				$("#editWindow").dialog('open');
			} else {
				$.messager.alert('提示', '请选中需要编辑的成绩', 'info');
			}
			$("#list").datagrid('reload');
		}
		
		function Edit() {
			var scoid = $("#escoid").val();
			var score = $("#ec").val();
			var sconame = $("#en").val();
			var stuid = $("#estuid").val();
			$.post('student/update',{'grade.scoid':scoid,"grade.stuid":stuid,'grade.score':score,'grade.sconame':sconame},"JSON");
			$("#list").datagrid('reload');
			$("#editWindow").dialog('close');
			$("#list").datagrid('reload');
		}
		
		function expurgate() {
			var row = $("#list").datagrid("getSelected");
			if (row) {
				$.post('student/delete',{'grade.scoid':row.scoid},"JSON");
				$("#list").datagrid('reload');
				$.messager.show({
					title:'提示消息',
					msg:'',
					showType:'show'
				});
				$("#list").datagrid('reload');
			} else {
				$.messager.alert('提示', '请选中需要删除的列', 'info');
			}
			$("#list").datagrid('reload');
		}
		
		function batchAdd() {
			var ids = [];
			var rows = $('#batchList').datagrid('getSelections');
			if (rows) {
				for(var i=0; i<rows.length; i++){
					ids.push(rows[i].intenid + rows[i].intenname);
				}
				alert(ids.join('\n'));
				$('#batchAdd').dialog('close');
				$('#addsWindow').dialog('open');
			} else {
				$.messager.alert('提示', '请选中需要添加的列', 'info');
			}
		}
		
		function studentname(value){
			return value.intenname;
		}

		</script>
</body>
</html>